/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package net.hnilica.cisteniulic.bean;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import net.hnilica.cisteniulic.dao.UliceDAO;
import net.hnilica.cisteniulic.dto.Ulice;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;

/**
 *
 * @author swosh
 */
public class NotWatchedUlice {
    private static final String defaultPartMunicipality = "BUBENEČ (PRAHA 7)";
    private static final int numColums = 10; //Number in column for test 3 for norm 100
    private String partMunicipality = defaultPartMunicipality;

    public Collection<String> getNotWatchedUlice() {

        UliceDAO uliceDAO = new UliceDAO();
        Subject subject = SecurityUtils.getSubject();
        //principal is sam as an email in database
        String principal = (String) subject.getPrincipal();

        Collection<Ulice> collUlice = uliceDAO.getNotWatchedUlice(principal, partMunicipality);
        Collection<String> listSb = new ArrayList<String>();

        int numThisColumn = 0;
        StringBuffer sb = new StringBuffer();
        int sizeCollUlice = collUlice.size();

        for (Iterator<Ulice> it = collUlice.iterator(); it.hasNext();) {

            Ulice ulice = it.next();
            if (numThisColumn == 0) {
                sb.append("<td><ul class='sprava_seznam'>");
            }
            numThisColumn++;
            sizeCollUlice--;
            sb.append("<li class='sprava_seznam'>");
            sb.append(ulice.getNazUlice().replaceFirst(" ", "&#160;"));
            sb.append("</li>");
            if (numThisColumn == numColums || sizeCollUlice == 0) {
                sb.append("</ul></td>");
                listSb.add(sb.toString());
                sb.delete(0, sb.length());
                numThisColumn = 0; // next iter starts in new td
            }
        }
        return listSb;
    }

    public String getPartMunicipality() {
        return partMunicipality;
    }
    public void setPartMunicipality(String partMunicipality) {
        this.partMunicipality = partMunicipality;
    }

}
